package dongtaiguihua;

public class _02走方格计数1 {
    //给定m和n，表示方格的行和列，1<=m、n<=100
    /*
    0,0,0
    0,1,0
    0,0,0    一代表障碍
     */
    public static void main(String[] args) {
        int[][] a = {
                 {0, 0, 0},
                 {0, 1, 0},
                 {0, 0, 0}
        };
        System.out.println(uniquePath(a));
    }

    private static Integer uniquePath(int[][] a) {
        int m = a.length;
        if (m == 0) {
            return 0;
        }
        int n = a[0].length;
        if (n == 0){
            return 0;
        }
        int[][] f = new int[m][n];
        for (int i = 0 ; i < m ;i ++){
            for (int j = 0 ; j < n ;j++){
                if (a[i][j] == 1){
                    f[i][j] = 0;
                }
                else {
                    if (i == 0 && j== 0){
                        f[i][j] = 1;
                    }
                    else {
                        f[i][j]=0;
                        if (i-1 >= 0){
                            f[i][j] += f[i-1][j];
                        }
                        if (j-1 >= 0){
                            f[i][j]+= f[i][j-1];
                        }
                    }
                }
            }
        }
        return f[m-1][n-1];
    }
}
